﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Data;

namespace SilverMap.Editor.Converters
{
	public class ItemAlignmentConverter : IValueConverter
	{

		#region IValueConverter Members

		public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
		{
			// value == Actual ItemAlignment value
			// parameter == Target ItemAlignment
			if (value == null || parameter == null)
				return false;

			if (value.GetType() != typeof(ItemAlignment))
				return false;

			var actualValue = (ItemAlignment)value;
			var targetValue = (ItemAlignment)Enum.Parse(typeof(ItemAlignment), parameter.ToString(), true);

			if (actualValue == targetValue)
				return true;

			return false;
		}

		public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
		{
			if (value == null || parameter == null)
				return null;

			bool? isChecked = (bool?)value;
			if (isChecked == true)
				return (ItemAlignment)Enum.Parse(typeof(ItemAlignment), parameter.ToString(), true);
			return null;
		}

		#endregion
	}
}
